/**
  * 提示 
  */
module game {

    export class TipMediator extends BaseMediator {
        public static NAME: string = "TipMediator";
        private obj: any;
        public constructor(viewComponent: any = null) {
            super(TipMediator.NAME, viewComponent);
        }

        public listNotificationInterests(): Array<any> {
            return [
                PanelNotify.HALL.STAGE_RESIZE,
                PanelNotify.HALL.OPEN_TIP,
                PanelNotify.HALL.CLOSE_TIP
            ];
        }
        private panel: TipPanel;
        public handleNotification(notification: puremvc.INotification): void {
            switch (notification.getName()) {
                case PanelNotify.HALL.STAGE_RESIZE:
                    if (this.panel) {
                        this.panel.width = GameConfig.curWidth()
                        this.panel.height = GameConfig.curHeight()
                    }
                    break;
                case PanelNotify.HALL.OPEN_TIP: {
                    this.obj = notification.getBody();
                    this.panel = null;
                    this.panel = new TipPanel();
                    this.showUI(this.panel, 2, 1, true, false);
                    break;
                }
                case PanelNotify.HALL.CLOSE_TIP: {
                    this.closePanel(0);
                    break;
                }
            }
        }

        /**
         * 初始化面板ui
         */
        public initUI(): void {
            this.panel.closeBtn.addEventListener(egret.TouchEvent.TOUCH_TAP, this.closeButtonClick, this);
            this.panel.confirm.addEventListener(egret.TouchEvent.TOUCH_TAP, this.confirmBrokeButtonClick, this);
        }

        /**
         * 初始化面板数据
         */
        public initData(): void {
            var code, text;
            if (Global.isNotEmpty(this.obj)) {
                code = this.obj[InstructionsEnum.CODE]
                text = this.obj[InstructionsEnum.TEXT]
            }
            if (Global.isNotEmpty(text)) {
                this.panel.tipText.text = text;
            }
            if (Global.isNotEmpty(code)) {
                this.panel.closeBtn.visible = true;
                this.panel.confirm.x = 280;
            } else {
                this.panel.closeBtn.visible = false;
                this.panel.confirm.x = 524;
            }
        }
        private closeButtonClick(event: egret.TouchEvent): void {
            SoundManage.startAnniuBtnLoad();
            this.closePanel(0);
        }

        private confirmBrokeButtonClick(event: egret.TouchEvent): void {
            SoundManage.startAnniuBtnLoad();
            this.closePanel(0);
            var code;
            if (Global.isNotEmpty(this.obj)) {
                code = this.obj[InstructionsEnum.CODE]
            }
            //重新登陆
            if (code == PanelNotify.HALL.RE_LOGIN) {
                game.AppFacade.instance.sendNotification(PanelNotify.LOGIN.OPEN_PLAYERLOGIN);
            } else if (code == PanelNotify.LOGIN.EXIT_GAME) { //退出游戏
                SocketManager.closeAllSocket()
            } else if (code == PanelNotify.BRNN.CLOSE_PLAY_GAME) {   //退出百人牛牛
                InstructionsEnum.isHall = false;
                if (BrnnVO.getVo().wTableId == undefined || BrnnVO.getVo().wTableId == 65535) {
                    SocketManager.closeSocket(InstructionsEnum.GAME_TYPE_NAME.BRNN)
                } else {
                    let data = {
                        wTableID: BrnnVO.getVo().wTableId,
                        wChairID: BrnnVO.getVo().wChairId,
                        cbForceLeave: 1
                    }
                    SocketManager.sendMessage(InstructionsEnum.GAME_TYPE_NAME.BRNN, RegDataGamePublic.CMD_GP_LeaveGame, data, true);
                }
            } else if (code == PanelNotify.DDZ.CLOSE_PLAY_GAME) { //退出斗地主
                InstructionsEnum.isHall = false;
                if (DdzVO.getVo().wTableId_my == undefined || DdzVO.getVo().wTableId_my == 65535) {
                    SocketManager.closeSocket(InstructionsEnum.GAME_TYPE_NAME.DDZ)
                } else {
                    let data = {
                        wTableID: DdzVO.getVo().wTableId_my,
                        wChairID: DdzVO.getVo().wChairId_my,
                        cbForceLeave: 1
                    }
                    SocketManager.sendMessage(InstructionsEnum.GAME_TYPE_NAME.DDZ, RegDataGamePublic.CMD_GP_LeaveGame, data, true);
                }
            } else if (code == PanelNotify.HLSZ.CLOSE_PLAY_GAME) {//退出扎金花
                InstructionsEnum.isHall = false;
                if (HlszVO.getVo().wTableId_2 == undefined || HlszVO.getVo().wTableId_2 == 65535) {
                    SocketManager.closeSocket(InstructionsEnum.GAME_TYPE_NAME.HLSZ)
                } else {
                    let data = {
                        wTableID: HlszVO.getVo().wTableId_2,
                        wChairID: HlszVO.getVo().wChairId_2,
                        cbForceLeave: 1
                    }
                    SocketManager.sendMessage(InstructionsEnum.GAME_TYPE_NAME.HLSZ, RegDataGamePublic.CMD_GP_LeaveGame, data, true);
                }
            } else if (code == PanelNotify.QZNN.CLOSE_PLAY_GAME) { //退出抢庄牛牛
                InstructionsEnum.isHall = false;
                if (QznnVO.getVo().wTableID == undefined || QznnVO.getVo().wTableID == 65535) {
                    SocketManager.closeSocket(InstructionsEnum.GAME_TYPE_NAME.QZNN)
                } else {
                    let data = {
                        wTableID: QznnVO.getVo().wTableID,
                        wChairID: QznnVO.getVo().wChairID,
                        cbForceLeave: 1
                    }
                    SocketManager.sendMessage(InstructionsEnum.GAME_TYPE_NAME.QZNN, RegDataGamePublic.CMD_GP_LeaveGame, data, true);
                }
            } else if (code == PanelNotify.WJL.CLOSE_PLAY_GAME) { //退出万家乐
                InstructionsEnum.isHall = false;
                if (WjlVO.getVo().wTableId == undefined || WjlVO.getVo().wTableId == 65535) {
                    SocketManager.closeSocket(InstructionsEnum.GAME_TYPE_NAME.WJL)
                } else {
                    let data = {
                        wTableID: WjlVO.getVo().wTableId,
                        wChairID: WjlVO.getVo().wChairId,
                        cbForceLeave: 1
                    }
                    SocketManager.sendMessage(InstructionsEnum.GAME_TYPE_NAME.WJL, RegDataGamePublic.CMD_GP_LeaveGame, data, true);
                }
            } else if (code == PanelNotify.LHD.CLOSE_PLAY_GAME) {//退出龙虎斗
                InstructionsEnum.isHall = false;
                if (LhdVO.getVo().wTableId == undefined || LhdVO.getVo().wTableId == 65535) {
                    SocketManager.closeSocket(InstructionsEnum.GAME_TYPE_NAME.LHD)
                } else {
                    let data = {
                        wTableID: LhdVO.getVo().wTableId,
                        wChairID: LhdVO.getVo().wChairId,
                        cbForceLeave: 1
                    }
                    SocketManager.sendMessage(InstructionsEnum.GAME_TYPE_NAME.LHD, RegDataGamePublic.CMD_GP_LeaveGame, data, true);
                }
            } else if (code == PanelNotify.HHDZ.CLOSE_PLAY_GAME) {  //退出红黑大战
                InstructionsEnum.isHall = false;
                if (HhdzVO.getVo().wTableId == undefined || HhdzVO.getVo().wTableId == 65535) {
                    SocketManager.closeSocket(InstructionsEnum.GAME_TYPE_NAME.HHDZ)
                } else {
                    let data = {
                        wTableID: HhdzVO.getVo().wTableId,
                        wChairID: HhdzVO.getVo().wChairId,
                        cbForceLeave: 1
                    }
                    SocketManager.sendMessage(InstructionsEnum.GAME_TYPE_NAME.HHDZ, RegDataGamePublic.CMD_GP_LeaveGame, data, true);
                }
            } else if (code == PanelNotify.HCJLB.CLOSE_PLAY_GAME) {  //退出豪车俱乐部
                InstructionsEnum.isHall = false;
                if (HcjlbVO.getVo().wTableId == undefined || HcjlbVO.getVo().wTableId == 65535) {
                    SocketManager.closeSocket(InstructionsEnum.GAME_TYPE_NAME.HCJLB)
                } else {
                    let data = {
                        wTableID: HcjlbVO.getVo().wTableId,
                        wChairID: HcjlbVO.getVo().wChairId,
                        cbForceLeave: 1
                    }
                    SocketManager.sendMessage(InstructionsEnum.GAME_TYPE_NAME.HCJLB, RegDataGamePublic.CMD_GP_LeaveGame, data, true);
                }
            } else if (code == PanelNotify.BREBG.CLOSE_PLAY_GAME) {//退出百人28杠
                InstructionsEnum.isHall = false;
                if (BrebgVO.getVo().wTableId == undefined || BrebgVO.getVo().wTableId == 65535) {
                    SocketManager.closeSocket(InstructionsEnum.GAME_TYPE_NAME.BREBG)
                } else {
                    let data = {
                        wTableID: BrebgVO.getVo().wTableId,
                        wChairID: BrebgVO.getVo().wChairId,
                        cbForceLeave: 1
                    }
                    SocketManager.sendMessage(InstructionsEnum.GAME_TYPE_NAME.BREBG, RegDataGamePublic.CMD_GP_LeaveGame, data, true);
                }
            } else if (code == PanelNotify.HALL.OPEN_ADD_MONEY) {//打开充值
                game.AppFacade.instance.sendNotification(PanelNotify.HALL.OPEN_ADD_MONEY);
            } else if (code == PanelNotify.HALL.REMOVE_ALL_MAIL) {//删除所有已读邮件
                game.AppFacade.instance.sendNotification(PanelNotify.HALL.REMOVE_ALL_MAIL);
            }
        }
    }
}